package com.d0320.Z20;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class HomeWork2 {
    public static void main(String[] args) throws IOException {
        int num = 0;
        byte[] buffer = new byte[1024];
        FileInputStream fis=null;
        File file = new File("src\\com\\d0320\\Z20\\CalcCharNum");
        try {
            file.createNewFile();
            System.out.println("创建文件成功");
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            fis = new FileInputStream(file);
            fis.read(buffer, 0, buffer.length);//读取文档的内容存到这个数组中
            for (int i = 0; i < buffer.length; i++) {
                if (buffer[i] == 'a' || buffer[i] == 'A') {
                    num++;
                }
            }
            System.out.println("A和a的数量为:"+num);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(null!= fis){
              fis.close();
            }
        }
    }
}